package routes

import (
	"gitee.com/igolang/imoney/internal/app/system/controllers"
	"gitee.com/igolang/imoney/internal/app/system/entities"
	"gitee.com/igolang/imoney/internal/app/system/entities/constants"
	"gitee.com/igolang/pkg/xgin"
)

func (r *router) common() {
	g := &xgin.RouterGroup{Name: "common", Group: r.g.Group("")}
	g.GET(xgin.RouteInfo{
		Name: "文件输出",
		Path: "profile/*filename",
	}, controllers.Common.Profile)

	g.GET(xgin.RouteInfo{
		Name: "下载文件",
		Path: "download",
		Ext: &entities.RoutePerm{
			Token:            true,
			OperationLogType: constants.OperationLogDownload,
		},
	}, controllers.Common.Resource)
	g.GET(xgin.RouteInfo{
		Name: "下载资源文件",
		Path: "download/resource",
		Ext: &entities.RoutePerm{
			Token:            true,
			OperationLogType: constants.OperationLogDownload,
		},
	}, controllers.Common.Resource)
	g.POST(xgin.RouteInfo{
		Name: "上传文件",
		Path: "upload",
		Ext: &entities.RoutePerm{
			Token:            true,
			OperationLogType: constants.OperationLogUpload,
		},
	}, controllers.Common.Upload)
	g.GET(xgin.RouteInfo{
		Name: "验证码",
		Path: "captchaImage",
	}, controllers.User.Captcha)

	g.POST(xgin.RouteInfo{
		Name: "登录",
		Path: "login",
	}, controllers.User.Login)

	g.POST(xgin.RouteInfo{
		Name: "登出",
		Path: "logout",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.User.Logout)

	g.GET(xgin.RouteInfo{
		Name: "用户信息",
		Path: "getInfo",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.User.LoginUser)

	g.GET(xgin.RouteInfo{
		Name: "动态路由",
		Path: "getRouters",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.Menu.Routers)
}

func (r *router) menu() {
	g := &xgin.RouterGroup{Name: "菜单管理", Group: r.g.Group("menu")}
	g.GET(xgin.RouteInfo{
		Name: "菜单列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "system:menu:list",
		},
	}, controllers.Menu.List)

	g.GET(xgin.RouteInfo{
		Name: "菜单详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "system:menu:list",
		},
	}, controllers.Menu.Detail)

	g.POST(xgin.RouteInfo{
		Name: "新增菜单",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "system:menu:add",
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Menu.Save)

	g.PUT(xgin.RouteInfo{
		Name: "编辑菜单",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "system:menu:edit",
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Menu.Save)

	g.DELETE(xgin.RouteInfo{
		Name: "删除菜单",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "system:menu:remove",
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Menu.Delete)

	g.GET(xgin.RouteInfo{
		Name: "菜单列表",
		Path: "treeselect",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.Menu.Tree)

	g.GET(xgin.RouteInfo{
		Name: "菜单列表",
		Path: "roleMenuTreeselect/:id",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.Menu.RoleMenu)
}

func (r *router) config() {
	g := &xgin.RouterGroup{Name: "参数管理", Group: r.g.Group("config")}
	g.GET(xgin.RouteInfo{
		Name: "参数列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:config:list",
			Token:      true,
		},
	}, controllers.Config.List)

	g.GET(xgin.RouteInfo{
		Name: "参数详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:config:list",
			Token:      true,
		},
	}, controllers.Config.Detail)

	g.GET(xgin.RouteInfo{
		Name: "获取参数值",
		Path: "configKey/:key",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.Config.Get)

	g.POST(xgin.RouteInfo{
		Name: "参数导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "system:config:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Config.Export)

	g.DELETE(xgin.RouteInfo{
		Name: "参数删除",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:config:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Config.Delete)

	g.DELETE(xgin.RouteInfo{
		Name: "刷新参数缓存",
		Path: "refreshCache",
		Ext: &entities.RoutePerm{
			Permission:       "system:config:remove",
			Token:            true,
			OperationLogType: constants.OperationLogClean,
		},
	}, controllers.Config.RefreshCache)

	g.POST(xgin.RouteInfo{
		Name: "新增参数",
		Ext: &entities.RoutePerm{
			Permission:       "system:config:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Config.Save)

	g.PUT(xgin.RouteInfo{
		Name: "编辑参数",
		Ext: &entities.RoutePerm{
			Permission:       "system:config:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Config.Save)
}

func (r *router) dict() {
	tg := &xgin.RouterGroup{Name: "字典管理", Group: r.g.Group("dict/type")}
	tg.GET(xgin.RouteInfo{
		Name: "字典列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:dict:list",
			Token:      true,
		},
	}, controllers.Dict.TypeList)

	tg.GET(xgin.RouteInfo{
		Name: "字典列表",
		Path: "optionselect",
		Ext: &entities.RoutePerm{
			Permission: "system:dict:list",
			Token:      true,
		},
	}, controllers.Dict.TypeOptionselect)

	tg.POST(xgin.RouteInfo{
		Name: "字典导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Dict.TypeExport)

	tg.DELETE(xgin.RouteInfo{
		Name: "刷新字典缓存",
		Path: "refreshCache",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:remove",
			Token:            true,
			OperationLogType: constants.OperationLogClean,
		},
	}, controllers.Dict.RefreshCache)

	tg.GET(xgin.RouteInfo{
		Name: "字典详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:dict:list",
			Token:      true,
		},
	}, controllers.Dict.TypeDetail)

	tg.POST(xgin.RouteInfo{
		Name: "新增字典",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Dict.TypeSave)
	tg.PUT(xgin.RouteInfo{
		Name: "编辑字典",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Dict.TypeSave)
	tg.DELETE(xgin.RouteInfo{
		Name: "删除字典",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Dict.TypeDelete)
	dg := &xgin.RouterGroup{Name: "字典管理", Group: r.g.Group("dict/data")}
	dg.GET(xgin.RouteInfo{
		Name: "字典数据列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:dict:list",
			Token:      true,
		},
	}, controllers.Dict.DataList)

	dg.POST(xgin.RouteInfo{
		Name: "字典数据导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Dict.DataExport)

	dg.GET(xgin.RouteInfo{
		Name: "字典数据详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:dict:list",
			Token:      true,
		},
	}, controllers.Dict.DataDetail)

	dg.POST(xgin.RouteInfo{
		Name: "新增字典数据",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Dict.DataSave)
	dg.PUT(xgin.RouteInfo{
		Name: "编辑字典数据",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Dict.DataSave)

	dg.DELETE(xgin.RouteInfo{
		Name: "删除字典数据",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:dict:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Dict.DataDelete)

	dg.GET(xgin.RouteInfo{
		Name: "字典数据",
		Path: "type/:type",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.Dict.DataGet)
}

// user 用户管理
func (r *router) user() {
	g := &xgin.RouterGroup{Name: "用户管理", Group: r.g.Group("user")}
	g.GET(xgin.RouteInfo{
		Name: "用户列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:user:list",
			Token:      true,
		},
	}, controllers.User.List)

	g.POST(xgin.RouteInfo{
		Name: "用户导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.User.Export)

	g.GET(xgin.RouteInfo{
		Name: "岗位及角色",
		Path: "/",
		Ext: &entities.RoutePerm{
			Permission: "system:user:list",
			Token:      true,
		},
	}, controllers.User.RoleAndPost)

	g.GET(xgin.RouteInfo{
		Name: "部门列表",
		Path: "deptTree",
		Ext: &entities.RoutePerm{
			Permission: "system:user:list",
			Token:      true,
		},
	}, controllers.User.DeptTree)

	g.GET(xgin.RouteInfo{
		Name: "用户详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:user:list",
			Token:      true,
		},
	}, controllers.User.Detail)

	g.GET(xgin.RouteInfo{
		Name: "个人信息",
		Path: "profile",
		Ext: &entities.RoutePerm{
			Token: true,
		},
	}, controllers.User.Profile)

	g.POST(xgin.RouteInfo{
		Name: "修改个人头像",
		Path: "profile/avatar",
		Ext: &entities.RoutePerm{
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.ProfileAvatar)

	g.PUT(xgin.RouteInfo{
		Name: "修改个人信息",
		Path: "profile",
		Ext: &entities.RoutePerm{
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.SaveProfile)

	g.PUT(xgin.RouteInfo{
		Name: "修改个人密码",
		Path: "profile/updatePwd",
		Ext: &entities.RoutePerm{
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.ProfileUpdatePwd)

	g.POST(xgin.RouteInfo{
		Name: "新增用户",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.User.Add)

	g.PUT(xgin.RouteInfo{
		Name: "修改用户",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.Update)

	g.PUT(xgin.RouteInfo{
		Name: "修改用户状态",
		Path: "changeStatus",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.ChangeStatus)

	g.GET(xgin.RouteInfo{
		Name: "用户分配角色",
		Path: "authRole/:id",
		Ext: &entities.RoutePerm{
			Permission: "system:user:edit",
			Token:      true,
		},
	}, controllers.User.AuthRoleList)

	g.PUT(xgin.RouteInfo{
		Name: "用户分配角色",
		Path: "authRole",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.AuthRole)

	g.PUT(xgin.RouteInfo{
		Name: "重置用户密码",
		Path: "resetPwd",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:resetPwd",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.User.ResetPwd)

	g.DELETE(xgin.RouteInfo{
		Name: "删除用户",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.User.Delete)

	g.POST(xgin.RouteInfo{
		Name: "解锁用户",
		Path: "unlock/:name",
		Ext: &entities.RoutePerm{
			Permission:       "system:user:unlock",
			Token:            true,
			OperationLogType: constants.OperationLogAuth,
		},
	}, controllers.User.LoginUnlock)
}

func (r *router) role() {
	g := &xgin.RouterGroup{Name: "角色管理", Group: r.g.Group("role")}
	g.GET(xgin.RouteInfo{
		Name: "角色列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:role:list",
			Token:      true,
		},
	}, controllers.Role.List)

	g.GET(xgin.RouteInfo{
		Name: "角色部门树",
		Path: "deptTree/:id",
		Ext: &entities.RoutePerm{
			Permission: "system:role:list",
			Token:      true,
		},
	}, controllers.Role.DeptTree)

	g.PUT(xgin.RouteInfo{
		Name: "角色状态变更",
		Path: "changeStatus",
		Ext: &entities.RoutePerm{
			Permission: "system:role:edit",
			Token:      true,
		},
	}, controllers.Role.ChangeStatus)

	g.GET(xgin.RouteInfo{
		Name: "角色详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:role:list",
			Token:      true,
		},
	}, controllers.Role.Detail)

	g.POST(xgin.RouteInfo{
		Name: "角色导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Role.Export)

	g.POST(xgin.RouteInfo{
		Name: "新增角色",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Role.Save)

	g.PUT(xgin.RouteInfo{
		Name: "编辑角色",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Role.Save)

	g.PUT(xgin.RouteInfo{
		Name: "角色数据权限",
		Path: "dataScope",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Role.DataScope)

	g.DELETE(xgin.RouteInfo{
		Name: "删除角色",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Role.Delete)

	ag := &xgin.RouterGroup{Name: "角色授权", Group: r.g.Group("role/authUser")}
	ag.GET(xgin.RouteInfo{
		Name: "已授权用户",
		Path: "allocatedList",
		Ext: &entities.RoutePerm{
			Permission: "system:role:edit",
			Token:      true,
		},
	}, controllers.Role.AllocatedList)

	ag.GET(xgin.RouteInfo{
		Name: "未授权用户",
		Path: "unallocatedList",
		Ext: &entities.RoutePerm{
			Permission: "system:role:edit",
			Token:      true,
		},
	}, controllers.Role.UnallocatedList)

	ag.PUT(xgin.RouteInfo{
		Name: "批量授权",
		Path: "selectAll",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:add",
			Token:            true,
			OperationLogType: constants.OperationLogAuth,
		},
	}, controllers.Role.AuthSelectAll)

	ag.PUT(xgin.RouteInfo{
		Name: "批量取消授权",
		Path: "cancelAll",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:remove",
			Token:            true,
			OperationLogType: constants.OperationLogAuth,
		},
	}, controllers.Role.AuthCancelAll)

	ag.PUT(xgin.RouteInfo{
		Name: "取消授权",
		Path: "cancel",
		Ext: &entities.RoutePerm{
			Permission:       "system:role:remove",
			Token:            true,
			OperationLogType: constants.OperationLogAuth,
		},
	}, controllers.Role.AuthCancel)

}

// post 岗位管理
func (r *router) post() {
	g := &xgin.RouterGroup{Name: "岗位管理", Group: r.g.Group("post")}
	g.GET(xgin.RouteInfo{
		Name: "岗位列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:post:list",
			Token:      true,
		},
	}, controllers.Post.List)

	g.POST(xgin.RouteInfo{
		Name: "岗位导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "system:post:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Post.Export)

	g.GET(xgin.RouteInfo{
		Name: "岗位详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:post:list",
			Token:      true,
		},
	}, controllers.Post.Detail)

	g.POST(xgin.RouteInfo{
		Name: "新增岗位",
		Ext: &entities.RoutePerm{
			Permission:       "system:post:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Post.Add)

	g.PUT(xgin.RouteInfo{
		Name: "修改岗位",
		Ext: &entities.RoutePerm{
			Permission:       "system:post:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Post.Update)

	g.DELETE(xgin.RouteInfo{
		Name: "删除岗位",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:post:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Post.Delete)

}

// dept 部门管理
func (r *router) dept() {
	g := &xgin.RouterGroup{Name: "部门管理", Group: r.g.Group("dept")}
	g.GET(xgin.RouteInfo{
		Name: "部门列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "system:dept:list",
		},
	}, controllers.Dept.List)

	g.GET(xgin.RouteInfo{
		Name: "部门列表",
		Path: "list/exclude/:id",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "system:dept:query",
		},
	}, controllers.Dept.ExcludeList)

	g.GET(xgin.RouteInfo{
		Name: "部门详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "system:dept:query",
		},
	}, controllers.Dept.Detail)

	g.POST(xgin.RouteInfo{
		Name: "添加部门",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "system:dept:add",
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Dept.Save)

	g.PUT(xgin.RouteInfo{
		Name: "修改部门",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "system:dept:edit",
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Dept.Save)

	g.DELETE(xgin.RouteInfo{
		Name: "删除部门",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "system:dept:remove",
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Dept.Delete)
}

// notice 通知公告
func (r *router) notice() {
	g := &xgin.RouterGroup{Name: "通知公告", Group: r.g.Group("notice")}
	g.GET(xgin.RouteInfo{
		Name: "通知列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "system:notice:list",
			Token:      true,
		},
	}, controllers.Notice.List)

	g.GET(xgin.RouteInfo{
		Name: "通知详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "system:notice:list",
			Token:      true,
		},
	}, controllers.Notice.Detail)

	g.POST(xgin.RouteInfo{
		Name: "新增通知",
		Ext: &entities.RoutePerm{
			Permission:       "system:notice:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Notice.Save)

	g.PUT(xgin.RouteInfo{
		Name: "修改通知",
		Ext: &entities.RoutePerm{
			Permission:       "system:notice:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Notice.Save)

	g.DELETE(xgin.RouteInfo{
		Name: "删除通知",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "system:notice:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Notice.Delete)
}
